using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dune.Business.Domain.Application;
using Dune.Business.Domain.Users;
using Edge.Business.Domain.Application;
using Edge.Common.ComponentModel.Notification;
using Edge.Common.Services;
using Edge.Common.Utils;
using Dune.Web.AppCode;
using Edge.WebCode;

namespace Dune.Web
{
    public partial class Dune : BaseMaster
    {
        private string personsList = "{";

        public string PersonsList
        {
            get { return personsList; }
            set { personsList = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Locator.GetService<IContextObjects>().Get<UserHolder>() != null)
            {
                User user = Locator.GetService<IContextObjects>().Get<UserHolder>().Object;
                foreach (Person pers in user.Persons)
                {
                    personsList += "'" + pers.Id.ToString() + "':'" + pers.Name + "',";
                }
                personsList += "}";
                Person person = Locator.GetService<IContextObjects>().Get<PersonHolder>().Object;
                Session[BasePage.LAST_ACTIVE] = DateTime.Now;
                phUser.Visible = true;
                lblLogin.Text = user.Email;
                lblPerson.Text = person.Name;
                phLogin.Visible = false;
                phUser.Visible = true;
            }
            else
            {
                phLogin.Visible = true;
                phUser.Visible = false;
            }
        }

        protected void btLogin_Click(object sender, EventArgs e)
        {
            Login<User,int>(tbLogin.Text, tbPasswd.Text);
        }

        protected void btLogout_Click(object sender, EventArgs e)
        {
            Locator.GetService<IContextObjects>().Set<UserHolder>(null);
            Locator.GetService<IContextObjects>().Set<PersonHolder>(null);
            Response.Redirect("Default.aspx");
        //    Response.Redirect(Page.Request.Url.AbsoluteUri);
        }

    }
}
